package com.atguigu.practice;

public class IsSubTreeOfTheAnotherTree {
    public boolean isSameTree(BinaryTree.TreeNode p, BinaryTree.TreeNode q){
        if(p==null&&q==null){
            return true;
        }
        if(p==null ||q==null){
            return false;
        }
        return p.val==q.val && isSameTree(p.left,q.left) &&isSameTree(p.right,q.right);
    }
    public boolean isSubTree(BinaryTree.TreeNode s, BinaryTree.TreeNode t){
        if(t==null) return true;
        if(s==null) return false;
        if(s.val==t.val&&isSameTree(s,t)){
            return true;
        }
        return isSubTree(s.left,t)||isSubTree(s.right,t);
    }
}
